import Vue from 'vue'
import VueRouter from 'vue-router'
import Home from '../views/Home.vue'
import Homepages from '@/components/Home.vue'
import baidu from '@/components/baidu.vue'
import tongji from '@/components/tongji.vue'
// 特效组
import SpecialEffects from '@/components/SpecialEffects.vue'
import Slide from '@/components/SpecialEffects/Slide.vue'
import LeftSlide from '@/components/SpecialEffects/Slide/LeftSlide.vue'
import RightSlide from '@/components/SpecialEffects/Slide/RightSlide.vue'
import TopSlide from '@/components/SpecialEffects/Slide/TopSlide.vue'
import loading from '../components/animation/loading.vue'
import globalChange from '@/untils/chageGlobal'
Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'Home',
    component: Home,
    children: [{
      path: 'home',
      name: 'Homepages',
      component: Homepages,
    }, {
      path: 'tongji',
      name: 'tongji',
      component: tongji,
    }, {
      path: 'baidu',
      name: 'baidu',
      component: baidu,
    },
    {
      path: 'SpecialEffects',
      component: SpecialEffects,
      children: [
        {
          path: 'Slide',
          component: Slide,
          children: [
            {
              path: 'LeftSlide',
              component: LeftSlide,
            },
            {
              path: 'RightSlide',
              component: RightSlide,
            },
            {
              path: 'TopSlide',
              component: TopSlide,
            },
          ]
        }, {
          path: 'loading',
          name: 'loading',
          component: loading,
        }
      ]
    },
    ]
  },
]
const router = new VueRouter({
  mode: 'hash',
  base: process.env.BASE_URL,
  routes
})
//获取原型对象上的push函数
const originalPush = VueRouter.prototype.push
//修改原型对象中的push方法
VueRouter.prototype.push = function push (location) {
  return originalPush.call(this, location).catch(err => err)
}
// 路由导航前置守卫
router.beforeEach((to, from, next) => {
  if (to.path == '/') {
    next({ path: '/tongji' })
    globalChange.changeTitle('贾坤朋的主页')
  }
  if (to.path.search("SpecialEffects") != -1) {
    globalChange.changeTitle('贾坤朋的特效页')
  }
  next();
})
export default router
